//错误提示框
function tip(content) {
	$(".alert-danger").text(content);
	$(".alert-danger").slideDown("normal", function() {
		$(".alert-danger").css("display", "inline");
	});
	var timeout = setTimeout(function() {
		$(".alert-danger").slideUp("normal", function() {
			$(".alert-danger").css("display", "none");
		});
	}, 3000);
};
angular.module("gzy", [ 'ngRoute' ]).directive("check", function($http) {
	return {
		require : 'ngModel',
		link : function() {
		}
	};
}).factory("s", function($rootScope) {
	return {
		status : true,
		status2 : true
	};
}).factory("v", function($rootScope) {
	return {
		username : "",
		password : ""
	};
}).controller("con1", function($scope, s, v, $http, $rootScope) {
	$scope.s = s;
	$scope.v = v;
	$scope.changeView1 = function() {
		$scope.v.username = "";
		$scope.v.password = "";
		s.status = !s.status;
	};
	$scope.changeView2 = function() {
		$scope.v.username = "";
		$scope.v.password = "";
		s.status2 = !s.status2;
	};
    $(".d1").bind("keydown",function(e){
        // 兼容FF和IE和Opera    
	    var theEvent = e || window.event;    
	    var code = theEvent.keyCode || theEvent.which || theEvent.charCode;    
	    if (code == 13) {    
	        //回车执行查询
	    	if($scope.s.status){
                $scope.login();
        	}
	    }    
	});
	$scope.login = function() {
		if($scope.v.username==null||$scope.v.username==""){
			tip("工号不能为空");
		}else if($scope.v.password==null||$scope.v.password==""){
			tip("密码不能为空");
		}else if($scope.v.password.length<6){
			tip("密码格式不正确");
		}else{
			// 有参数 Post请求
			$http({
				method : 'post',
				url : 'login/login',
				params : {
					"username" : $scope.v.username,
					"pwd" : $scope.v.password,
					"type":0
				}
			}).then(function successCallback(response) {
				console.log(response.data);
				// 请求成功执行代码
				if (response.data.code == 1) {
					window.location.href = "staff.html";
				} else {
					tip("用户名或密码错误！！");
				}
			}, function errorCallback(response) {
				// 请求失败执行代码
				tip("请求失败");
			});
		}
	};
}).controller("con2", function($scope, s, v, $http) {
	var temp = "";
	$scope.zy = false;
	$scope.s = s;
	$scope.z = false;
	$scope.checkstr = function() {
		if ($scope.str == temp) {
			$scope.z = true;
		}
	}
	$scope.changeView1 = function() {
		$scope.username1 = "";
		$scope.password1 = "";
		$scope.password2 = "";
		s.status = !s.status;
	};
    $(".d2").bind("keydown",function(e){
        // 兼容FF和IE和Opera    
	    var theEvent = e || window.event;    
	    var code = theEvent.keyCode || theEvent.which || theEvent.charCode;    
	    if (code == 13) {    
	        //回车执行查询
	    	if(!$scope.s.status){
                $scope.adminLogin();
        	}
	    }    
	});
	$scope.adminLogin = function() {
		if( $scope.username1==null|| $scope.username1==""){
			tip("工号不能为空");
		}else if($scope.password1==null||$scope.password1==""){
			tip("密码不能为空");
		}else if($scope.password1.length<6){
			tip("密码格式不正确");
		}else{
			// 有参数 Post请求
			$http({
				method : 'post',
				url : 'login/login',
				params : {
					"username" : $scope.username1,
					"pwd" : $scope.password1,
					"type":1
				}
			}).then(function successCallback(response) {
				console.log(response.data);
				// 请求成功执行代码
				if (response.data.code == 1) {
					window.location.href = "index.html";
				} else {
					tip("用户名或密码错误！！");
				}
			}, function errorCallback(response) {
				// 请求失败执行代码
				tip("请求失败");
			});
		}
		
	};

})
